package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.ActivityManagement;
import com.ruoyi.system.domain.MeetingManagement;
import com.ruoyi.system.service.IActivityManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动管理Controller
 *
 * @author ruoyi
 * @date 2024-04-02
 */
@RestController
@RequestMapping("/system/activity/management")
public class ActivityManagementController extends BaseController
{
    @Autowired
    private IActivityManagementService activityManagementService;

    /**
     * 查询活动管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ActivityManagement activityManagement)
    {
        setStartPage(activityManagement.getPageNum(),activityManagement.getPageSize());
        List<ActivityManagement> list = activityManagementService.selectActivityManagementList(activityManagement);
        return getDataTable(list);
    }

    /**
     * 获取活动管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(activityManagementService.selectActivityManagementById(id));
    }

    /**
     * 新增活动管理
     */
    @PreAuthorize("@ss.hasPermi('system:management:add')")
    @Log(title = "活动管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ActivityManagement activityManagement)
    {
        activityManagement.setCreateBy(String.valueOf(getUserId()));
        return activityManagementService.insertActivityManagement(activityManagement);
    }

    /**
     * 修改活动管理
     */
    @PreAuthorize("@ss.hasPermi('system:management:edit')")
    @Log(title = "活动管理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ActivityManagement activityManagement)
    {
        activityManagement.setUpdateBy(getUsername());
        return toAjax(activityManagementService.updateActivityManagement(activityManagement));
    }

    /**
     * 删除活动管理
     */
    @PreAuthorize("@ss.hasPermi('system:management:remove')")
    @Log(title = "活动管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(activityManagementService.deleteActivityManagementById(id));
    }

    /**
     * 查询活动活动签到统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @PostMapping("/signaturelist")
    public TableDataInfo signaturelist(@RequestBody ActivityManagement activityManagement)
    {
        setStartPage(activityManagement.getPageNum(),activityManagement.getPageSize());
        List<ActivityManagement> list = activityManagementService.selectActivitySignaturelist(activityManagement);
        return getDataTable(list);
    }

    /**
     * 导出活动通知
     */
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @PostMapping("/exportNotify")
    public AjaxResult exportNotify(@RequestBody ActivityManagement activityManagement, HttpServletResponse response)
    {
        return activityManagementService.exportActivityNotify(activityManagement,response);
    }

    /**
     * 导出活动签到列表
     */
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @PostMapping("/exportSignature")
    public AjaxResult exportSignature(@RequestBody ActivityManagement activityManagement,HttpServletResponse response)
    {
        return activityManagementService.exportActivitySignature(activityManagement,response);
    }

    /**
     * 党建大数据 活动分布
     */
    @GetMapping("/activityStructure/{queryYear}")
    public AjaxResult activityStructure(@PathVariable String queryYear)
    {
        if(StringUtils.isBlank(queryYear)){
            queryYear = DateUtils.getNowYear();
        }
        return success(activityManagementService.activityStructure(queryYear));
    }
}
